#include "StdAfx.h"
#include "PictureImpl.h"

PictureImpl::PictureImpl()
	: mWidth(0),
	  mHeight(0)
{}

int PictureImpl::GetRawWidth() const
{
	return mWidth;
}

int PictureImpl::GetRawHeight() const
{
	return mHeight;
}

int PictureImpl::GetBytesInRow() const
{
	// the number of bytes in mWidth pixels is aligned up
	// to the DWORD boundary (the number which is multiple of 4)
	return (mWidth * GetOffsetX() + 3) & (~3);
}

int PictureImpl::GetOffsetX() const
{
	return 3; // three components: red, green, blue; one byte each
}

int PictureImpl::GetOffsetY() const
{
	// the next row of pixels have incremented y-coordinates
	// (x, y) -> (x, y + 1)
	return GetBytesInRow();
}

/*
Grants the read/write access to the image bytes.
*/
BYTE* PictureImpl::GetData()
{
	return mData.empty() ? NULL : &mData[0];
}

const BYTE* PictureImpl::GetData() const
{
	return mData.empty() ? NULL : &mData[0];
}

/*
Resizes the image. The original information is lost.
*/
void PictureImpl::SetWidthHeight(int width, int height)
{
	mWidth = width;
	mHeight = height;
	mData.resize(GetBytesInRow() * mHeight);
}

/*
Resets the image information
*/
void PictureImpl::CleanUp()
{
	mWidth = mHeight = 0;	
	mData.clear();
}